package com.penjin.android.utils;

import android.content.Context;
import android.text.Html;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.penjin.android.R;

public class ToastHelper {


    public static void showMessage(String msg, Context context) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    public static void showNoNetwork(Context context) {
        Toast.makeText(context, "当前网络 不可用", Toast.LENGTH_SHORT).show();
    }

    public static void showConnectionError(Context context) {
        Toast.makeText(context, "网络连接异常", Toast.LENGTH_SHORT).show();
    }

    public static void showNotLogin(Context context) {
        Toast.makeText(context, "用户尚未登录", Toast.LENGTH_SHORT).show();
    }

    /**
     * 服务器内部错误
     *
     * @param context
     */
    public static void showServerError(Context context) {
        Toast.makeText(context, "服务器内部错误，请稍后重试!", Toast.LENGTH_SHORT).show();
    }

    public static void showJsonError(Context context) {
        Toast.makeText(context, "格式解析错误", Toast.LENGTH_SHORT).show();
    }

    public static void showNotBindCompany(Context context) {
        Toast.makeText(context, "尚未绑定公司", Toast.LENGTH_SHORT).show();
    }

    public static void showDNSError(Context context) {
        Toast.makeText(context, "服务器地址出错!", Toast.LENGTH_SHORT).show();
    }

    public static void showAlertMessage(Context context, int resId, String message) {
        View view = LayoutInflater.from(context.getApplicationContext()).inflate(resId, null);
        ((TextView) view.findViewById(R.id.text)).setText(Html.fromHtml(message));
        Toast toast = new Toast(context);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
